home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / adb / a-tiwtio < prev    next >
Text File  |  1996-02-12  |  30KB  |  1,107 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --             A D A . T E X T _ I O . W I D E _ T E X T _ I O              --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.11 $                             --
  10. --                                                                          --
  11. --   Copyright (C) 1992,1993,1994,1995,1996 Free Software Foundation, Inc.  --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with Ada.Streams;          use Ada.Streams;
  37. with Interfaces.C_Streams; use Interfaces.C_Streams;
  38. with System;
  39. with System.File_IO;
  40. with System.WCh_Cnv;       use System.WCh_Cnv;
  41. with System.WCh_Con;       use System.WCh_Con;
  42. with Unchecked_Conversion;
  43. with Unchecked_Deallocation;
  44.  
  45. pragma Elaborate_All (System.File_IO);
  46. --  Needed because of calls to Chain_File in package body elaboration
  47.  
  48. package body Ada.Text_IO.Wide_Text_IO is
  49.  
  50.    package FIO renames System.File_IO;
  51.    package TIO renames Ada.Text_IO;
  52.  
  53.    subtype AP is FCB.AFCB_Ptr;
  54.  
  55.    function To_FCB is new Unchecked_Conversion (File_Mode, FCB.File_Mode);
  56.    function To_TIO is new Unchecked_Conversion (FCB.File_Mode, File_Mode);
  57.    use type FCB.File_Mode;
  58.  
  59.    -----------------------
  60.    -- Local Subprograms --
  61.    -----------------------
  62.  
  63.    function Get_Wide_Char
  64.      (C    : Character;
  65.       File : File_Type)
  66.       return Wide_Character;
  67.    --  This function is shared by Get and Get_Immediate to extract a wide
  68.    --  character value from the given File. The first byte has already been
  69.    --  read and is passed in C. The wide character value is returned as the
  70.    --  result, and the file pointer is bumped past the character.
  71.  
  72.    -------------------
  73.    -- AFCB_Allocate --
  74.    -------------------
  75.  
  76.    function AFCB_Allocate
  77.      (Control_Block : Wide_Text_AFCB)
  78.       return          FCB.AFCB_Ptr
  79.    is
  80.    begin
  81.       return new Wide_Text_AFCB;
  82.    end AFCB_Allocate;
  83.  
  84.    ----------------
  85.    -- AFCB_Close --
  86.    ----------------
  87.  
  88.    procedure AFCB_Close (File : access Wide_Text_AFCB) is
  89.    begin
  90.       --  If the file being closed is one of the current files, then close
  91.       --  the corresponding current file. It is not clear that this action
  92.       --  is required (RM A.10.3(23)) but it seems reasonable, and besides
  93.       --  ACVC test CE3208A expects this behavior).
  94.  
  95.       if File = Current_In then
  96.          Current_In := null;
  97.       elsif File = Current_Out then
  98.          Current_Out := null;
  99.       elsif File = Current_Err then
  100.          Current_Err := null;
  101.       end if;
  102.  
  103.       --  Output line terminator if needed, but page terminator is implied
  104.  
  105.       if File.Mode /= FCB.In_File
  106.         and then File.Col /= 1
  107.       then
  108.          New_Line (File);
  109.       end if;
  110.    end AFCB_Close;
  111.  
  112.    ---------------
  113.    -- AFCB_Free --
  114.    ---------------
  115.  
  116.    procedure AFCB_Free (File : access Wide_Text_AFCB) is
  117.       type FCB_Ptr is access all Wide_Text_AFCB;
  118.       FT : FCB_Ptr := File;
  119.  
  120.       procedure Free is new
  121.         Unchecked_Deallocation (Wide_Text_AFCB, FCB_Ptr);
  122.  
  123.    begin
  124.       Free (FT);
  125.    end AFCB_Free;
  126.  
  127.    -----------
  128.    -- Close --
  129.    -----------
  130.  
  131.    procedure Close (File : in out File_Type) is
  132.    begin
  133.       FIO.Close (AP (File));
  134.    end Close;
  135.  
  136.    ---------
  137.    -- Col --
  138.    ---------
  139.  
  140.    --  Note: we assume that it is impossible in practice for the column
  141.    --  to exceed the value of Count'Last, i.e. no check is required for
  142.    --  overflow raising layout error.
  143.  
  144.    function Col (File : in File_Type) return Positive_Count is
  145.    begin
  146.       return Positive_Count (TIO.Col (TIO.File_Type (File)));
  147.    end Col;
  148.  
  149.    function Col return Positive_Count is
  150.    begin
  151.       return Col (Current_Out);
  152.    end Col;
  153.  
  154.    ------------
  155.    -- Create --
  156.    ------------
  157.  
  158.    procedure Create
  159.      (File : in out File_Type;
  160.       Mode : in File_Mode := Out_File;
  161.       Name : in String := "";
  162.       Form : in String := "")
  163.    is
  164.       File_Control_Block : Wide_Text_AFCB;
  165.  
  166.    begin
  167.       FIO.Open (File_Ptr  => AP (File),
  168.                 Dummy_FCB => File_Control_Block,
  169.                 Mode      => To_FCB (Mode),
  170.                 Name      => Name,
  171.                 Form      => Form,
  172.                 Amethod   => 'W',
  173.                 Creat     => True,
  174.                 Text      => True);
  175.  
  176.       Setup (File);
  177.    end Create;
  178.  
  179.    -------------------
  180.    -- Current_Error --
  181.    -------------------
  182.  
  183.    function Current_Error return File_Type is
  184.    begin
  185.       return Current_Err;
  186.    end Current_Error;
  187.  
  188.    function Current_Error return File_Access is
  189.    begin
  190.       return Current_Err'Access;
  191.    end Current_Error;
  192.  
  193.    -------------------
  194.    -- Current_Input --
  195.    -------------------
  196.  
  197.    function Current_Input return File_Type is
  198.    begin
  199.       return Current_In;
  200.    end Current_Input;
  201.  
  202.    function Current_Input return File_Access is
  203.    begin
  204.       return Current_In'Access;
  205.    end Current_Input;
  206.  
  207.    --------------------
  208.    -- Current_Output --
  209.    --------------------
  210.  
  211.    function Current_Output return File_Type is
  212.    begin
  213.       return Current_Out;
  214.    end Current_Output;
  215.  
  216.    function Current_Output return File_Access is
  217.    begin
  218.       return Current_Out'Access;
  219.    end Current_Output;
  220.  
  221.    ------------
  222.    -- Delete --
  223.    ------------
  224.  
  225.    procedure Delete (File : in out File_Type) is
  226.    begin
  227.       FIO.Delete (AP (File));
  228.    end Delete;
  229.  
  230.    -----------------
  231.    -- End_Of_File --
  232.    -----------------
  233.  
  234.    function End_Of_File (File : in File_Type) return Boolean is
  235.    begin
  236.       return TIO.End_Of_File (TIO.File_Type (File));
  237.    end End_Of_File;
  238.  
  239.    function End_Of_File return Boolean is
  240.    begin
  241.       return TIO.End_Of_File (TIO.File_Type (Current_In));
  242.    end End_Of_File;
  243.  
  244.    -----------------
  245.    -- End_Of_Line --
  246.    -----------------
  247.  
  248.    function End_Of_Line (File : in File_Type) return Boolean is
  249.    begin
  250.       FIO.Check_Read_Status (AP (File));
  251.  
  252.       if File.Before_Wide_Character then
  253.          return False;
  254.       else
  255.          return TIO.End_Of_Line (TIO.File_Type (File));
  256.       end if;
  257.    end End_Of_Line;
  258.  
  259.    function End_Of_Line return Boolean is
  260.    begin
  261.       return End_Of_Line (Current_In);
  262.    end End_Of_Line;
  263.  
  264.    -----------------
  265.    -- End_Of_Page --
  266.    -----------------
  267.  
  268.    function End_Of_Page (File : in File_Type) return Boolean is
  269.    begin
  270.       FIO.Check_Read_Status (AP (File));
  271.  
  272.       if File.Before_Wide_Character then
  273.          return False;
  274.       else
  275.          return TIO.End_Of_Page (TIO.File_Type (File));
  276.       end if;
  277.    end End_Of_Page;
  278.  
  279.    function End_Of_Page return Boolean is
  280.    begin
  281.       return End_Of_Page (Current_In);
  282.    end End_Of_Page;
  283.  
  284.    -----------
  285.    -- Flush --
  286.    -----------
  287.  
  288.    procedure Flush (File : in out File_Type) is
  289.    begin
  290.       FIO.Flush (AP (File));
  291.    end Flush;
  292.  
  293.    procedure Flush is
  294.    begin
  295.       Flush (Current_Out);
  296.    end Flush;
  297.  
  298.    ----------
  299.    -- Form --
  300.    ----------
  301.  
  302.    function Form (File : in File_Type) return String is
  303.    begin
  304.       return FIO.Form (AP (File));
  305.    end Form;
  306.  
  307.    ---------
  308.    -- Get --
  309.    ---------
  310.  
  311.    procedure Get
  312.      (File : in File_Type;
  313.       Item : out Wide_Character)
  314.    is
  315.       C  : Character;
  316.  
  317.    begin
  318.       FIO.Check_Read_Status (AP (File));
  319.  
  320.       if File.Before_Wide_Character then
  321.          File.Before_Wide_Character := False;
  322.          Item := File.Saved_Wide_Character;
  323.  
  324.       else
  325.          TIO.Get (TIO.File_Type (File), C);
  326.          Item := Get_Wide_Char (C, File);
  327.       end if;
  328.    end Get;
  329.  
  330.    procedure Get (Item : out Wide_Character) is
  331.    begin
  332.       Get (Current_In, Item);
  333.    end Get;
  334.  
  335.    procedure Get
  336.      (File : in File_Type;
  337.       Item : out Wide_String)
  338.    is
  339.    begin
  340.       for J in Item'Range loop
  341.          Get (File, Item (J));
  342.       end loop;
  343.    end Get;
  344.  
  345.    procedure Get (Item : out Wide_String) is
  346.    begin
  347.       Get (Current_In, Item);
  348.    end Get;
  349.  
  350.    -------------------
  351.    -- Get_Immediate --
  352.    -------------------
  353.  
  354.    --  More work required here ???
  355.  
  356.    procedure Get_Immediate
  357.      (File : in File_Type;
  358.       Item : out Wide_Character)
  359.    is
  360.       ch : int;
  361.  
  362.    begin
  363.       FIO.Check_Read_Status (AP (File));
  364.  
  365.       if File.Before_Wide_Character then
  366.          File.Before_Wide_Character := False;
  367.          Item := File.Saved_Wide_Character;
  368.  
  369.       elsif File.Before_LM then
  370.          File.Before_LM := False;
  371.          File.Before_LM_PM := False;
  372.          Item := Wide_Character'Val (LM);
  373.  
  374.       else
  375.          ch := Getc (TIO.File_Type (File));
  376.  
  377.          if ch = EOF then
  378.             raise End_Error;
  379.          else
  380.             Item := Get_Wide_Char (Character'Val (ch), File);
  381.          end if;
  382.       end if;
  383.    end Get_Immediate;
  384.  
  385.    procedure Get_Immediate
  386.      (Item : out Wide_Character)
  387.    is
  388.    begin
  389.       Get_Immediate (Current_In, Item);
  390.    end Get_Immediate;
  391.  
  392.    procedure Get_Immediate
  393.      (File      : in File_Type;
  394.       Item      : out Wide_Character;
  395.       Available : out Boolean)
  396.    is
  397.       ch : int;
  398.  
  399.    begin
  400.       FIO.Check_Read_Status (AP (File));
  401.       Available := True;
  402.  
  403.       if File.Before_Wide_Character then
  404.          File.Before_Wide_Character := False;
  405.          Item := File.Saved_Wide_Character;
  406.  
  407.       elsif File.Before_LM then
  408.          File.Before_LM := False;
  409.          File.Before_LM_PM := False;
  410.          Item := Wide_Character'Val (LM);
  411.  
  412.       else
  413.          ch := Getc (TIO.File_Type (File));
  414.  
  415.          if ch = EOF then
  416.             raise End_Error;
  417.          else
  418.             Item := Get_Wide_Char (Character'Val (ch), File);
  419.          end if;
  420.       end if;
  421.    end Get_Immediate;
  422.  
  423.    procedure Get_Immediate
  424.      (Item      : out Wide_Character;
  425.       Available : out Boolean)
  426.    is
  427.    begin
  428.       Get_Immediate (Current_In, Item, Available);
  429.    end Get_Immediate;
  430.  
  431.    --------------
  432.    -- Get_Line --
  433.    --------------
  434.  
  435.    procedure Get_Line
  436.      (File : in File_Type;
  437.       Item : out Wide_String;
  438.       Last : out Natural)
  439.    is
  440.    begin
  441.       FIO.Check_Read_Status (AP (File));
  442.       Last := Item'First - 1;
  443.  
  444.       --  Immediate exit for null string, this is a case in which we do not
  445.       --  need to test for end of file and we do not skip a line mark under
  446.       --  any circumstances.
  447.  
  448.       if Last >= Item'Last then
  449.          return;
  450.       end if;
  451.  
  452.       --  Here we have at least one character, if we are immediately before
  453.       --  a line mark, then we will just skip past it storing no characters.
  454.  
  455.       if File.Before_LM then
  456.          File.Before_LM := False;
  457.          File.Before_LM_PM := False;
  458.  
  459.       --  Otherwise we need to read some characters
  460.  
  461.       else
  462.          --  If we are at the end of file now, it means we are trying to
  463.          --  skip a file terminator and we raise End_Error (RM A.10.7(20))
  464.  
  465.          if Nextc (TIO.File_Type (File)) = EOF then
  466.             raise End_Error;
  467.          end if;
  468.  
  469.          --  Loop through characters in string
  470.  
  471.          loop
  472.             --  Exit the loop if read is terminated by encountering line mark
  473.             --  Note that the use of Skip_Line here ensures we properly deal
  474.             --  with setting the page and line numbers.
  475.  
  476.             if End_Of_Line (File) then
  477.                Skip_Line (File);
  478.                return;
  479.             end if;
  480.  
  481.             --  Otherwise store the character, note that we know that ch is
  482.             --  something other than LM or EOF. It could possibly be a page
  483.             --  mark if there is a stray page mark in the middle of a line,
  484.             --  but this is not an official page mark in any case, since
  485.             --  official page marks can only follow a line mark. The whole
  486.             --  page business is pretty much nonsense anyway, so we do not
  487.             --  want to waste time trying to make sense out of non-standard
  488.             --  page marks in the file! This means that the behavior of
  489.             --  Get_Line is different from repeated Get of a character, but
  490.             --  that's too bad. We only promise that page numbers etc make
  491.             --  sense if the file is formatted in a standard manner.
  492.  
  493.             --  Note: we do not adjust the column number because it is quicker
  494.             --  to adjust it once at the end of the operation than incrementing
  495.             --  it each time around the loop.
  496.  
  497.             Last := Last + 1;
  498.             Get (File, Item (Last));
  499.  
  500.             --  All done if the string is full, this is the case in which
  501.             --  we do not skip the following line mark. We need to adjust
  502.             --  the column number in this case.
  503.  
  504.             if Last = Item'Last then
  505.                File.Col := File.Col + TIO.Count (Item'Length);
  506.                return;
  507.             end if;
  508.  
  509.             --  Exit from the loop if we are at the end of file. This happens
  510.             --  if we have a last line that is not terminated with a line mark.
  511.             --  In this case we consider that there is an implied line mark;
  512.             --  this is a non-standard file, but we will treat it nicely.
  513.  
  514.             exit when Nextc (TIO.File_Type (File)) = EOF;
  515.          end loop;
  516.       end if;
  517.    end Get_Line;
  518.  
  519.    procedure Get_Line
  520.      (Item : out Wide_String;
  521.       Last : out Natural)
  522.    is
  523.    begin
  524.       Get_Line (Current_In, Item, Last);
  525.    end Get_Line;
  526.  
  527.    -------------------
  528.    -- Get_Wide_Char --
  529.    -------------------
  530.  
  531.    function Get_Wide_Char
  532.      (C    : Character;
  533.       File : File_Type)
  534.       return Wide_Character
  535.    is
  536.       function In_Char return Character;
  537.       --  Function used to obtain additional characters it the wide character
  538.       --  sequence is more than one character long.
  539.  
  540.       function In_Char return Character is
  541.          ch : constant Integer := Getc (TIO.File_Type (File));
  542.  
  543.       begin
  544.          if ch = EOF then
  545.             raise End_Error;
  546.          else
  547.             return Character'Val (ch);
  548.          end if;
  549.       end In_Char;
  550.  
  551.       function WC_In is new Char_Sequence_To_Wide_Char (In_Char);
  552.  
  553.    begin
  554.       return WC_In (C, File.WC_Method);
  555.    end Get_Wide_Char;
  556.  
  557.    -------------
  558.    -- Is_Open --
  559.    -------------
  560.  
  561.    function Is_Open (File : in File_Type) return Boolean is
  562.    begin
  563.       return FIO.Is_Open (AP (File));
  564.    end Is_Open;
  565.  
  566.    ----------
  567.    -- Line --
  568.    ----------
  569.  
  570.    --  Note: we assume that it is impossible in practice for the line
  571.    --  to exceed the value of Count'Last, i.e. no check is required for
  572.    --  overflow raising layout error.
  573.  
  574.    function Line (File : in File_Type) return Positive_Count is
  575.    begin
  576.       return Positive_Count (TIO.Line (TIO.File_Type (File)));
  577.    end Line;
  578.  
  579.    function Line return Positive_Count is
  580.    begin
  581.       return Line (Current_Out);
  582.    end Line;
  583.  
  584.    -----------------
  585.    -- Line_Length --
  586.    -----------------
  587.  
  588.    function Line_Length (File : in File_Type) return Count is
  589.    begin
  590.       return Count (TIO.Line_Length (TIO.File_Type (File)));
  591.    end Line_Length;
  592.  
  593.    function Line_Length return Count is
  594.    begin
  595.       return Line_Length (Current_Out);
  596.    end Line_Length;
  597.  
  598.    ----------------
  599.    -- Look_Ahead --
  600.    ----------------
  601.  
  602.    procedure Look_Ahead
  603.      (File        : in File_Type;
  604.       Item        : out Wide_Character;
  605.       End_Of_Line : out Boolean)
  606.    is
  607.       ch : int;
  608.  
  609.    --  Start of processing for Look_Ahead
  610.  
  611.    begin
  612.       FIO.Check_Read_Status (AP (File));
  613.  
  614.       --  If we are logically before a line mark, we can return immediately
  615.  
  616.       if File.Before_LM then
  617.          End_Of_Line := True;
  618.          Item := Wide_Character'Val (0);
  619.  
  620.       --  If we are before a wide character, just return it (this happens
  621.       --  if there are two calls to Look_Ahead in a row).
  622.  
  623.       elsif File.Before_Wide_Character then
  624.          End_Of_Line := False;
  625.          Item := File.Saved_Wide_Character;
  626.  
  627.       --  otherwise we must read a character from the input stream
  628.  
  629.       else
  630.          ch := Getc (TIO.File_Type (File));
  631.  
  632.          if ch = LM
  633.            or else ch = EOF
  634.            or else (ch = EOF and then File.Is_Regular_File)
  635.          then
  636.             End_Of_Line := True;
  637.             Ungetc (ch, TIO.File_Type (File));
  638.             Item := Wide_Character'Val (0);
  639.  
  640.          --  If the character is in the range 16#0000# to 16#007F# it stands
  641.          --  for itself and occupies a single byte, so we can unget it with
  642.          --  no difficulty.
  643.  
  644.          elsif ch <= 16#0080# then
  645.             End_Of_Line := False;
  646.             Ungetc (ch, TIO.File_Type (File));
  647.             Item := Wide_Character'Val (ch);
  648.  
  649.          --  For a character above this range, we read the character, using
  650.          --  the Get_Wide_Char routine. It may well occupy more than one byte
  651.          --  so we can't put it back with ungetc. Instead we save it in the
  652.          --  control block, setting a flag that everyone interested in reading
  653.          --  characters must test before reading the stream.
  654.  
  655.          else
  656.             Item := Get_Wide_Char (Character'Val (ch), File);
  657.             End_Of_Line := False;
  658.             File.Saved_Wide_Character := Item;
  659.             File.Before_Wide_Character := True;
  660.          end if;
  661.       end if;
  662.    end Look_Ahead;
  663.  
  664.    procedure Look_Ahead
  665.      (Item        : out Wide_Character;
  666.       End_Of_Line : out Boolean)
  667.    is
  668.    begin
  669.       Look_Ahead (Standard_In, Item, End_Of_Line);
  670.    end Look_Ahead;
  671.  
  672.    ----------
  673.    -- Mode --
  674.    ----------
  675.  
  676.    function Mode (File : in File_Type) return File_Mode is
  677.    begin
  678.       return To_TIO (FIO.Mode (AP (File)));
  679.    end Mode;
  680.  
  681.    ----------
  682.    -- Name --
  683.    ----------
  684.  
  685.    function Name (File : in File_Type) return String is
  686.    begin
  687.       return FIO.Name (AP (File));
  688.    end Name;
  689.  
  690.    --------------
  691.    -- New_Line --
  692.    --------------
  693.  
  694.    procedure New_Line
  695.      (File    : in File_Type;
  696.       Spacing : in Positive_Count := 1)
  697.    is
  698.    begin
  699.       TIO.New_Line (TIO.File_Type (File), TIO.Positive_Count (Spacing));
  700.    end New_Line;
  701.  
  702.    procedure New_Line (Spacing : in Positive_Count := 1) is
  703.    begin
  704.       New_Line (Current_Out, Spacing);
  705.    end New_Line;
  706.  
  707.    --------------
  708.    -- New_Page --
  709.    --------------
  710.  
  711.    procedure New_Page (File : in File_Type) is
  712.    begin
  713.       TIO.New_Page (TIO.File_Type (File));
  714.    end New_Page;
  715.  
  716.    procedure New_Page is
  717.    begin
  718.       New_Page (Current_Out);
  719.    end New_Page;
  720.  
  721.    ----------
  722.    -- Open --
  723.    ----------
  724.  
  725.    procedure Open
  726.      (File : in out File_Type;
  727.       Mode : in File_Mode;
  728.       Name : in String;
  729.       Form : in String := "")
  730.    is
  731.       File_Control_Block : Wide_Text_AFCB;
  732.  
  733.    begin
  734.       FIO.Open (File_Ptr  => AP (File),
  735.                 Dummy_FCB => File_Control_Block,
  736.                 Mode      => To_FCB (Mode),
  737.                 Name      => Name,
  738.                 Form      => Form,
  739.                 Amethod   => 'T',
  740.                 Creat     => False,
  741.                 Text      => True);
  742.  
  743.       Setup (File);
  744.    end Open;
  745.  
  746.    ----------
  747.    -- Page --
  748.    ----------
  749.  
  750.    --  Note: we assume that it is impossible in practice for the page
  751.    --  to exceed the value of Count'Last, i.e. no check is required for
  752.    --  overflow raising layout error.
  753.  
  754.    function Page (File : in File_Type) return Positive_Count is
  755.    begin
  756.       return Positive_Count (TIO.Page (TIO.File_Type (File)));
  757.    end Page;
  758.  
  759.    function Page return Positive_Count is
  760.    begin
  761.       return Page (Current_Out);
  762.    end Page;
  763.  
  764.    -----------------
  765.    -- Page_Length --
  766.    -----------------
  767.  
  768.    function Page_Length (File : in File_Type) return Count is
  769.    begin
  770.       return Count (TIO.Page_Length (TIO.File_Type (File)));
  771.    end Page_Length;
  772.  
  773.    function Page_Length return Count is
  774.    begin
  775.       return Page_Length (Current_Out);
  776.    end Page_Length;
  777.  
  778.    ---------
  779.    -- Put --
  780.    ---------
  781.  
  782.    procedure Put
  783.      (File : in File_Type;
  784.       Item : in Wide_Character)
  785.    is
  786.       procedure Out_Char (C : Character);
  787.       --  Procedure to output one character of a wide character sequence
  788.  
  789.       procedure Out_Char (C : Character) is
  790.       begin
  791.          Putc (Character'Pos (C), TIO.File_Type (File));
  792.       end Out_Char;
  793.  
  794.       procedure WC_Out is new Wide_Char_To_Char_Sequence (Out_Char);
  795.  
  796.    begin
  797.       WC_Out (Item, File.WC_Method);
  798.       File.Col := File.Col + 1;
  799.    end Put;
  800.  
  801.    procedure Put (Item : in Wide_Character) is
  802.    begin
  803.       Put (Current_Out, Item);
  804.    end Put;
  805.  
  806.    ---------
  807.    -- Put --
  808.    ---------
  809.  
  810.    procedure Put
  811.      (File : in File_Type;
  812.       Item : in Wide_String)
  813.    is
  814.    begin
  815.       for J in Item'Range loop
  816.          Put (File, Item (J));
  817.       end loop;
  818.    end Put;
  819.  
  820.    procedure Put (Item : in Wide_String) is
  821.    begin
  822.       Put (Current_Out, Item);
  823.    end Put;
  824.  
  825.    --------------
  826.    -- Put_Line --
  827.    --------------
  828.  
  829.    procedure Put_Line
  830.      (File : in File_Type;
  831.       Item : in Wide_String)
  832.    is
  833.    begin
  834.       Put (File, Item);
  835.       New_Line (File);
  836.    end Put_Line;
  837.  
  838.    procedure Put_Line (Item : in Wide_String) is
  839.    begin
  840.       Put (Current_Out, Item);
  841.       New_Line (Current_Out);
  842.    end Put_Line;
  843.  
  844.    -----------
  845.    -- Reset --
  846.    -----------
  847.  
  848.    procedure Reset
  849.      (File : in out File_Type;
  850.       Mode : in File_Mode)
  851.    is
  852.       function To_TIO_Mode is
  853.         new Unchecked_Conversion (File_Mode, TIO.File_Mode);
  854.  
  855.    begin
  856.       TIO.Reset (TIO.File_Type (File), To_TIO_Mode (Mode));
  857.       File.Before_Wide_Character := False;
  858.    end Reset;
  859.  
  860.    procedure Reset (File : in out File_Type) is
  861.    begin
  862.       TIO.Reset (TIO.File_Type (File));
  863.       File.Before_Wide_Character := False;
  864.    end Reset;
  865.  
  866.    -------------
  867.    -- Set_Col --
  868.    -------------
  869.  
  870.    procedure Set_Col
  871.      (File : in File_Type;
  872.       To   : in Positive_Count)
  873.    is
  874.    begin
  875.       TIO.Set_Col (TIO.File_Type (File), TIO.Positive_Count (To));
  876.    end Set_Col;
  877.  
  878.    procedure Set_Col (To : in Positive_Count) is
  879.    begin
  880.       Set_Col (Current_Out, To);
  881.    end Set_Col;
  882.  
  883.    ---------------
  884.    -- Set_Error --
  885.    ---------------
  886.  
  887.    procedure Set_Error (File : in File_Type) is
  888.    begin
  889.       FIO.Check_Write_Status (AP (File));
  890.       Current_Err := File;
  891.    end Set_Error;
  892.  
  893.    ---------------
  894.    -- Set_Input --
  895.    ---------------
  896.  
  897.    procedure Set_Input (File : in File_Type) is
  898.    begin
  899.       FIO.Check_Read_Status (AP (File));
  900.       Current_In := File;
  901.    end Set_Input;
  902.  
  903.    --------------
  904.    -- Set_Line --
  905.    --------------
  906.  
  907.    procedure Set_Line
  908.      (File : in File_Type;
  909.       To   : in Positive_Count)
  910.    is
  911.    begin
  912.       TIO.Set_Line (TIO.File_Type (File), TIO.Positive_Count (To));
  913.       File.Before_Wide_Character := False;
  914.    end Set_Line;
  915.  
  916.    procedure Set_Line (To : in Positive_Count) is
  917.    begin
  918.       Set_Line (Current_Out, To);
  919.    end Set_Line;
  920.  
  921.    ---------------------
  922.    -- Set_Line_Length --
  923.    ---------------------
  924.  
  925.    procedure Set_Line_Length (File : in File_Type; To : in Count) is
  926.    begin
  927.       TIO.Set_Line_Length (TIO.File_Type (File), TIO.Count (To));
  928.    end Set_Line_Length;
  929.  
  930.    procedure Set_Line_Length (To : in Count) is
  931.    begin
  932.       Set_Line_Length (Current_Out, To);
  933.    end Set_Line_Length;
  934.  
  935.    ----------------
  936.    -- Set_Output --
  937.    ----------------
  938.  
  939.    procedure Set_Output (File : in File_Type) is
  940.    begin
  941.       FIO.Check_Write_Status (AP (File));
  942.       Current_Out := File;
  943.    end Set_Output;
  944.  
  945.    ---------------------
  946.    -- Set_Page_Length --
  947.    ---------------------
  948.  
  949.    procedure Set_Page_Length (File : in File_Type; To : in Count) is
  950.    begin
  951.       TIO.Set_Page_Length (TIO.File_Type (File), TIO.Count (To));
  952.    end Set_Page_Length;
  953.  
  954.    procedure Set_Page_Length (To : in Count) is
  955.    begin
  956.       Set_Page_Length (Current_Out, To);
  957.    end Set_Page_Length;
  958.  
  959.    -----------
  960.    -- Setup --
  961.    -----------
  962.  
  963.    procedure Setup (File : File_Type) is
  964.       Start, Stop : Natural;
  965.  
  966.    begin
  967.       FIO.Form_Parameter (File.Form.all, "wcem", Start, Stop);
  968.  
  969.       if Start = 0 then
  970.          null;
  971.  
  972.       elsif Start /= Stop then
  973.          raise Use_Error;
  974.  
  975.       else
  976.          for J in WC_Encoding_Method loop
  977.             if File.Form (Start) = WC_Encoding_Letters (J) then
  978.                File.WC_Method := J;
  979.                return;
  980.             end if;
  981.          end loop;
  982.  
  983.          raise Use_Error;
  984.       end if;
  985.  
  986.    end Setup;
  987.  
  988.    ---------------
  989.    -- Skip_Line --
  990.    ---------------
  991.  
  992.    procedure Skip_Line
  993.      (File    : in File_Type;
  994.       Spacing : in Positive_Count := 1)
  995.    is
  996.    begin
  997.       TIO.Skip_Line (TIO.File_Type (File), TIO.Positive_Count (Spacing));
  998.       File.Before_Wide_Character := False;
  999.    end Skip_Line;
  1000.  
  1001.    procedure Skip_Line (Spacing : in Positive_Count := 1) is
  1002.    begin
  1003.       Skip_Line (Current_In, Spacing);
  1004.    end Skip_Line;
  1005.  
  1006.    ---------------
  1007.    -- Skip_Page --
  1008.    ---------------
  1009.  
  1010.    procedure Skip_Page (File : in File_Type) is
  1011.    begin
  1012.       TIO.Skip_Page (TIO.File_Type (File));
  1013.       File.Before_Wide_Character := False;
  1014.    end Skip_Page;
  1015.  
  1016.    procedure Skip_Page is
  1017.    begin
  1018.       Skip_Page (Current_In);
  1019.    end Skip_Page;
  1020.  
  1021.    --------------------
  1022.    -- Standard_Error --
  1023.    --------------------
  1024.  
  1025.    function Standard_Error return File_Type is
  1026.    begin
  1027.       return Standard_Err;
  1028.    end Standard_Error;
  1029.  
  1030.    function Standard_Error return File_Access is
  1031.    begin
  1032.       return Standard_Err'Access;
  1033.    end Standard_Error;
  1034.  
  1035.    --------------------
  1036.    -- Standard_Input --
  1037.    --------------------
  1038.  
  1039.    function Standard_Input return File_Type is
  1040.    begin
  1041.       return Standard_In;
  1042.    end Standard_Input;
  1043.  
  1044.    function Standard_Input return File_Access is
  1045.    begin
  1046.       return Standard_In'Access;
  1047.    end Standard_Input;
  1048.  
  1049.    ---------------------
  1050.    -- Standard_Output --
  1051.    ---------------------
  1052.  
  1053.    function Standard_Output return File_Type is
  1054.    begin
  1055.       return Standard_Out;
  1056.    end Standard_Output;
  1057.  
  1058.    function Standard_Output return File_Access is
  1059.    begin
  1060.       return Standard_Out'Access;
  1061.    end Standard_Output;
  1062.  
  1063. begin
  1064.    -------------------------------
  1065.    -- Initialize Standard Files --
  1066.    -------------------------------
  1067.  
  1068.    --  Note: the names in these files are bogus, and probably it would be
  1069.    --  better for these files to have no names, but the ACVC test insist!
  1070.    --  We use names that are bound to fail in open etc.
  1071.  
  1072.    Standard_In.Stream             := stdin;
  1073.    Standard_In.Name               := new String'("*stdin");
  1074.    Standard_In.Form               := Null_Str'Unrestricted_Access;
  1075.    Standard_In.Mode               := FCB.In_File;
  1076.    Standard_In.Is_Regular_File    := is_regular_file (fileno (stdin)) /= 0;
  1077.    Standard_In.Is_Temporary_File  := False;
  1078.    Standard_In.Is_System_File     := True;
  1079.    Standard_In.Is_Text_File       := True;
  1080.    Standard_In.Access_Method      := 'W';
  1081.  
  1082.    Standard_Out.Stream            := stdout;
  1083.    Standard_Out.Name              := new String'("*stdout");
  1084.    Standard_Out.Form              := Null_Str'Unrestricted_Access;
  1085.    Standard_Out.Mode              := FCB.Out_File;
  1086.    Standard_Out.Is_Regular_File   := is_regular_file (fileno (stdout)) /= 0;
  1087.    Standard_Out.Is_Temporary_File := False;
  1088.    Standard_Out.Is_System_File    := True;
  1089.    Standard_Out.Is_Text_File      := True;
  1090.    Standard_Out.Access_Method     := 'W';
  1091.  
  1092.    Standard_Err.Stream            := stderr;
  1093.    Standard_Err.Name              := new String'("*stderr");
  1094.    Standard_Err.Form              := Null_Str'Unrestricted_Access;
  1095.    Standard_Err.Mode              := FCB.Out_File;
  1096.    Standard_Err.Is_Regular_File   := is_regular_file (fileno (stderr)) /= 0;
  1097.    Standard_Err.Is_Temporary_File := False;
  1098.    Standard_Err.Is_System_File    := True;
  1099.    Standard_Err.Is_Text_File      := True;
  1100.    Standard_Err.Access_Method     := 'W';
  1101.  
  1102.    FIO.Chain_File (AP (Standard_In));
  1103.    FIO.Chain_File (AP (Standard_Out));
  1104.    FIO.Chain_File (AP (Standard_Err));
  1105.  
  1106. end Ada.Text_IO.Wide_Text_IO;
  1107.